using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using XPTable;
using XPTable.Editors;
using XPTable.Models;

namespace View
{
	/// <summary>
	/// Summary description for AddPayeeDialog.
	/// </summary>
	public class AddPayeeDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private PinkieControls.ButtonXP cancelButton;
		private PinkieControls.ButtonXP addButton;
		private System.Windows.Forms.TextBox otherTextBox;
		private XPTable.Models.Table payeesTable;
		private System.Windows.Forms.TextBox amountTextBox;
		private System.Windows.Forms.Label totalAmountLabel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AddPayeeDialog(XPTable.Models.Table pTable, System.Windows.Forms.Label label)
		{
			payeesTable = pTable;
			totalAmountLabel = label;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.label2 = new System.Windows.Forms.Label();
			this.otherTextBox = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.amountTextBox = new System.Windows.Forms.TextBox();
			this.cancelButton = new PinkieControls.ButtonXP();
			this.addButton = new PinkieControls.ButtonXP();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(88, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Select a payee:";
			// 
			// listBox1
			// 
			this.listBox1.Items.AddRange(new object[] {
														  "(Other Payee)",
														  "Shiv",
														  "Wissam",
														  "Mustansir",
														  "Amr",
														  "Abdel"});
			this.listBox1.Location = new System.Drawing.Point(96, 32);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(168, 56);
			this.listBox1.TabIndex = 1;
			this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 96);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "If other:";
			// 
			// otherTextBox
			// 
			this.otherTextBox.Enabled = false;
			this.otherTextBox.Location = new System.Drawing.Point(96, 96);
			this.otherTextBox.Name = "otherTextBox";
			this.otherTextBox.Size = new System.Drawing.Size(168, 20);
			this.otherTextBox.TabIndex = 3;
			this.otherTextBox.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 128);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(80, 23);
			this.label3.TabIndex = 4;
			this.label3.Text = "Amount spent:";
			// 
			// amountTextBox
			// 
			this.amountTextBox.Location = new System.Drawing.Point(96, 128);
			this.amountTextBox.Name = "amountTextBox";
			this.amountTextBox.Size = new System.Drawing.Size(168, 20);
			this.amountTextBox.TabIndex = 5;
			this.amountTextBox.Text = "";
			// 
			// cancelButton
			// 
			this.cancelButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.cancelButton.DefaultScheme = true;
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.cancelButton.Hint = "";
			this.cancelButton.Location = new System.Drawing.Point(149, 168);
			this.cancelButton.Name = "cancelButton";
			this.cancelButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.cancelButton.Size = new System.Drawing.Size(104, 24);
			this.cancelButton.TabIndex = 20;
			this.cancelButton.Text = "Cancel";
			this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
			// 
			// addButton
			// 
			this.addButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.addButton.DefaultScheme = true;
			this.addButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.addButton.Hint = "";
			this.addButton.Location = new System.Drawing.Point(37, 168);
			this.addButton.Name = "addButton";
			this.addButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.addButton.Size = new System.Drawing.Size(104, 24);
			this.addButton.TabIndex = 19;
			this.addButton.Text = "Add";
			this.addButton.Click += new System.EventHandler(this.addButton_Click);
			// 
			// AddPayeeDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(290, 216);
			this.Controls.Add(this.cancelButton);
			this.Controls.Add(this.addButton);
			this.Controls.Add(this.amountTextBox);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.otherTextBox);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "AddPayeeDialog";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Add payee";
			this.ResumeLayout(false);

		}
		#endregion

		private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(listBox1.GetSelected(0))
				otherTextBox.Enabled = true;
			else
				otherTextBox.Enabled = false;

		}

		private void cancelButton_Click(object sender, System.EventArgs e)
		{
			this.Dispose();
		}

		private void addButton_Click(object sender, System.EventArgs e)
		{
			int totalRow = payeesTable.TableModel.Rows.Count;
			string name;
			double amount, totalAmount;
			
			if(listBox1.GetSelected(0))
				name = otherTextBox.Text;
			else
				name = listBox1.Text;
			
			totalAmount = Convert.ToDouble(totalAmountLabel.Text);
			amount = Convert.ToDouble(amountTextBox.Text);
			totalAmount += amount;
			totalAmountLabel.Text = totalAmount.ToString();
			payeesTable.TableModel.Rows.Insert((totalRow+1), new Row(new Cell[] {
																							  new Cell(name),
																							  new Cell(amount)
																						  }));
			this.Dispose();
		}
	}
}
